import { Body, Controller, Get, HttpException, HttpStatus, Patch } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { DetailPageService } from './detail-page.service'
import { UpdateDetailPageDto } from './dto/detail-page.dto'

@ApiTags('后台/详情页配置')
@Controller('admin/detail-page')
export class DetailPageController {
  constructor(private readonly detailPageService: DetailPageService) {}
  /**
   * 获取详情页配置
   */
  @Get()
  detail() {
    return this.detailPageService.findOne({})
  }

  /**
   * 更新详情页配置
   */
  @Patch()
  async update(
    @Body()
    data: UpdateDetailPageDto,
  ) {
    const findData = await this.detailPageService.findOne({})
    if (!findData) {
      throw new HttpException('详情页配置不存在', HttpStatus.NOT_FOUND)
    }
    await this.detailPageService.update(findData.detailPageId, data)
  }
}

@ApiTags('官网/详情页配置')
@Controller('web/detail-page')
export class WebDetailPageController {
  constructor(private readonly detailPageService: DetailPageService) {}

  /**
   * 获取详情页配置
   */
  @Get()
  webDetail() {
    return this.detailPageService.findOne({})
  }
}
